package com.sebscape.sebcms;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sebscape.sebcms.persistence.dao.GenericDao;
import com.sebscape.sebcms.security.domain.User;

public class testservlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7986058970069040551L;

	/* (non-Javadoc)
	 * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		GenericDao<User, Long> dao = new GenericDao<User, Long>( User.class );
		User user = new User("sbelt", "Slappy", "password", "Steve", "Belt", "sbelt@sebscape.com" );
		dao.save( user );
		// did it work?
		List<User> list = dao.findAll();
		resp.setContentType( "text/html");
		resp.getOutputStream().println( "size is now: " + list.size() + "<br/>");
		for( User u: list ){
			resp.getOutputStream().println( u.getName() + "<br/>");
			resp.getOutputStream().println( u.getDescription() + "<br/>");
			resp.getOutputStream().println( u.getPassword() + "<br/>");
			resp.getOutputStream().println( u.getFirstname() + "<br/>");
			resp.getOutputStream().println( u.getLastname() + "<br/>");
			resp.getOutputStream().println( u.getEmailAddress() + "<br/>");
		}
		
	}
	
}
